<template>
  <div>
    <PageDialog
      :title="dialogInfo.title"
      v-model:visible="shows"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
    >
      <DialogTable
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :check-box="false"
        :tab-index="true"
        :listen-height="false"
        :pager="false"
        :summary="true"
        :summary-field-list="tableInfo.summaryFieldList"
        v-model:query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        @handleEvent="handleEvent"
      >
      </DialogTable>
    </PageDialog>
  </div>
</template>

<script setup name="IndividualDetails">
import { getSmartCabinetStockCustomizeListAll } from '@/api/smartCabinet.js'
import { getCustomizeSetting } from '@/api/customize'
const { proxy } = getCurrentInstance()
const props = defineProps({
  showDialog: {
    type: Boolean,
  },
  query: {
    type: Object,
    default: function () {
      return {}
    },
  },
})
// 过滤相关配置
const filterInfo = ref({
  query: {
    curPage: 1,
    pageSize: 99999,
    queryMap: {
      ...props.query,
    },
    customizeUserVO: {},
  },
  list: [],
})
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  copyData: [],
  api: undefined,
  selections: [],
  fieldList: [],
  summaryFieldList: [
    { value: 'qty', formatter: proxy.$fn.qtyFormatter },
    { value: 'sumAmount', formatter: proxy.$fn.TripartiteMethod },
  ],
  handle: {},
})
// 弹窗相关
const dialogInfo = ref({
  title: '个体详情',
  btLoading: false,
  btList: [{ label: '关闭', event: handleClose, show: true }],
})
const shows = computed({
  get() {
    return props.showDialog
  },
  set(val) {
    proxy.$emit('update:showDialog', val) // 更新父组件visible
  },
})

onMounted(() => {
  let obj = {}
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  getCustomize()
})
function getList() {
  tableInfo.value.refresh = Math.random()
}
// 关闭弹窗前的回调
function handleClose() {
  shows.value = false
  proxy.$emit('reset')
}
function getCustomize() {
  let param = {
    tableKey:
      'singleSmartCabinetStockDetail-com.slip.spd.entity.vo.smartCabinet.SmartCabinetStockVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = res.data
      tableInfo.value.fieldList = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail
      )
      tableInfo.value.api = getSmartCabinetStockCustomizeListAll
      getList()
    }
  })
}
</script>

<style scoped lang="scss">
:deep(.filter-item) {
  width: 100%;
}
</style>
